package com.ruoyi.project.cms.notice.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.notice.domain.CmsNotice;
import com.ruoyi.project.cms.notice.domain.ECharts;
import com.ruoyi.project.cms.notice.domain.NoticeType;
import com.ruoyi.project.cms.notice.service.CmsNoticeService;
import com.ruoyi.project.cms.notice.service.NoticeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * com.ruoyi.project.cms.notice.controller
 * 作者：lh
 * 描述:
 * 时间:2020-05-18
 */
@Controller
@RequestMapping("/notice/eCharts")
class TestEChartsController extends BaseController {

    private String prefix = "cms/notice";

    @Autowired
    private CmsNoticeService cmsNoticeService;

    @Autowired
    private NoticeTypeService typeService;

    @GetMapping("")
    public String type()
    {
        return prefix + "/testecharts";
    }

    /**
     * 获取图数据
     */
    @PostMapping("/getOption")
    @ResponseBody
    public TableDataInfo getOption(ECharts eCharts){
        startPage();
        List<ECharts> list2=new ArrayList<>();
        int number=0;
        int number2=0;
        //获取所有的公告类型
        List<NoticeType> list= typeService.selectAll();
        for (NoticeType t:list){
            //根据公告类型id获取对应的公告
            List<CmsNotice> list1=cmsNoticeService.selectByTp(t.getTid());
            for(CmsNotice c:list1){
                number++;
                number2 =number2+c.getNpageviews();
            }
            list2.add(new ECharts(t.getTname(),number,number2));
            //添加完成之后清零
            number=0;
            number2=0;
        }
        return getDataTable(list2);
    }
}
